package friendsbtt.core.lang;

import java.util.List;
import java.util.ArrayList;

public class CustomList<T> extends ArrayList<T> {
	
	public CustomList<T> where(IFilter<T> filter){
		CustomList<T> filtered = new CustomList<T>();
		for (T t : this) {
			if(filter.isTrue(t)){
				filtered.add(t);
			}
		}
		return filtered;
	}
	
	public T firstOrDefault(IFilter<T> filter){
		T first = null;
		for (T t : this) {
			if(filter.isTrue(t)){
				first = t;
				break;
			}
		}
		return first;
	}
	
	public CustomList<T> skip(int count){
		CustomList<T> res = new CustomList<T>();
		if(this.size() < count){
			for(int i = 0; (i + count) < res.size() && i < count; i++){
				res.add(this.get(i + count));
			}
			return res;
		}
		else {
			return res;
		}
	}
	
	public CustomList<T> take(int count){
		CustomList<T> res = new CustomList<T>();
		for(int i = 0; i < count && i < this.size(); i++){
			res.add(this.get(i));
		}
		return res;
	}
}
